package com.wangshouyu.mp.user.tag;

import com.wangshouyu.mp.base.request.HttpMethod;
import com.wangshouyu.mp.base.request.MpClient;
import com.wangshouyu.mp.base.request.RequestBody;
import com.wangshouyu.mp.base.response.BaseResponse;
import com.wangshouyu.mp.utils.GsonUtils;

import java.text.MessageFormat;

import static com.wangshouyu.mp.base.constant.UrlConstant.*;

/**
 * @author 王守钰
 * @date 2020年12月23日 14:57
 * @description 标签处理器
 */
public class TagHandler {

    private TagHandler() {
    }

    /**
     * 创建
     * @param mpClient 客户端
     * @param tag 标签
     * @param accessToken token
     * @return 标签信息
     */
    public static TagResponse create(MpClient mpClient, TagRequest tag, String accessToken){
        String url = MessageFormat.format(CREATE_TAG_URL, accessToken);
        return mpClient.request(HttpMethod.POST,
                url,
                RequestBody.create(GsonUtils.toJson(tag)),
                TagResponse.class);
    }

    /**
     * 修改
     * @param mpClient 客户端
     * @param tag 标签
     * @param accessToken token
     * @return 标签信息
     */
    public static BaseResponse update(MpClient mpClient, TagRequest tag, String accessToken){
        String url = MessageFormat.format(UPDATE_TAG_URL, accessToken);
        return mpClient.request(HttpMethod.POST,
                url,
                RequestBody.create(GsonUtils.toJson(tag)),
                BaseResponse.class);
    }

    /**
     * 列表
     * @param mpClient 客户端
     * @param accessToken token
     * @return 标签信息
     */
    public static TagListResponse list(MpClient mpClient, String accessToken){
        String url = MessageFormat.format(GET_TAG_URL, accessToken);
        return mpClient.request(HttpMethod.GET, url, TagListResponse.class);
    }

    /**
     * 删除标签
     * @param mpClient 客户端
     * @param tag 标签
     * @param accessToken token
     * @return 结果
     */
    public static BaseResponse del(MpClient mpClient, TagRequest tag, String accessToken){
        String url = MessageFormat.format(DEL_TAG_URL, accessToken);
        return mpClient.request(HttpMethod.POST,
                url,
                RequestBody.create(GsonUtils.toJson(tag)),
                BaseResponse.class);
    }

    /**
     * 标签用户列表
     * @param mpClient 客户端
     * @param tagUser 标签用户
     * @param accessToken token
     * @return 标签用户列表
     */
    public static TagUserResponse queryTagUser(MpClient mpClient, TagUserRequest tagUser, String accessToken){
        String url = MessageFormat.format(QUERY_TAG_USER_UEL, accessToken);
        return mpClient.request(HttpMethod.POST,
                url,
                RequestBody.create(GsonUtils.toJson(tagUser)),
                TagUserResponse.class);
    }


    /**
     * 标签用户
     * @param mpClient 客户端
     * @param tagUser 标签用户
     * @param accessToken token
     * @return 结果
     */
    public static BaseResponse tagUser(MpClient mpClient, TagUserRequest tagUser, String accessToken){
        String url = MessageFormat.format(TAG_USER_URL, accessToken);
        return mpClient.request(HttpMethod.POST,
                url,
                RequestBody.create(GsonUtils.toJson(tagUser)),
                BaseResponse.class);
    }

    /**
     * 标签用户
     * @param mpClient 客户端
     * @param tagUser 标签用户
     * @param accessToken token
     * @return 结果
     */
    public static BaseResponse unTagUser(MpClient mpClient, TagUserRequest tagUser, String accessToken){
        String url = MessageFormat.format(UN_TAG_USER_URL, accessToken);
        return mpClient.request(HttpMethod.POST,
                url,
                RequestBody.create(GsonUtils.toJson(tagUser)),
                BaseResponse.class);
    }

    /**
     * 用户身上的标签
     * @param mpClient 客户端
     * @param userTagRequest 用户标签
     * @param accessToken token
     * @return 标签列表
     */
    public static UserTagResponse userTag(MpClient mpClient, UserTagRequest userTagRequest, String accessToken){
        String url = MessageFormat.format(USER_TAG_URL, accessToken);
        return mpClient.request(HttpMethod.POST,
                url,
                RequestBody.create(GsonUtils.toJson(userTagRequest)),
                UserTagResponse.class);
    }
}
